package com.jack.leetcode.eachProblem07;

/**
 * Created by zhang_j on 2020/7/28
 */
public class 二叉树的最大深度 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }

    public static int maxDepth(TreeNode root) {
        if(root == null){
            return 0;
        }

        return deepth(root, 0);
    }

    private static int deepth(TreeNode root, int deepth){
        if(root == null){
            return deepth;
        }
        return Math.max(deepth(root.left, deepth+1), deepth(root.right, deepth+1));
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.left.left = new TreeNode(3);
        System.out.println(maxDepth(root));
    }
}
